﻿//============================================
// filename: main.c
// chip    : CSU8RP3216
// author  :
// date    : 2022-05-19
//============================================
#include "CSU8RP3216.h"
#include "DevicesDelay.h"
#include "DevicesTimer.h"
#include "DevicesWatchDog.h"
#include "DevicesSoftTimer.h"
#include "DevicesLed.h"
#include "DevicesBlower.h"
#include "DevicesPower.h"
#include "DevicesADC.h"

//============================================
// interrupt function
//============================================
void INT_FUNCTION(void) interrupt
{
    if(TM4IF != 0)
    {
        TM4IF = 0;

        vTimer4Interrupt();
    }
}

void vUserSystemInit(void)
{
    /* 系统1us时基 */
    vTime4Init();

    vPowerInit();

    vBlowerACInit();

    vLedInit();

    vADCInit();

    vWatchdogInit();

    /* 使能全局中断 */
    GIE = 1;
}

int32_t g_iVoltage;    /* mV */
int32_t g_iCurrent;    /* mA */

//============================================
// program start
//============================================
void main(void)
{
    MCK = 0x80;

    vUserSystemInit();

    while(1)
    {
        g_iVoltage = iADCGetValue(ADC_DMA_CHANNEL_VOLTAGE);
        g_iCurrent = iADCGetValue(ADC_DMA_CHANNEL_CURRENT);

        // vPowerMachine();

        vBlowerMachine();

        vLedMachine();

        /* 喂狗 */
        vWatchdogReload();
    }
}
